package config;

import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;

@Configuration
@ComponentScan("com.guigu.www")
@MapperScan("com.guigu.www.dao.mapper")
public class Spring {

    /*-------------------------------------------mybatis-------------------------------------------*/
    private final String DRIVERCLASS = "com.mysql.jdbc.Driver";
    private final String JDBCURL = "jdbc:mysql://49.235.89.147:3306/yb_zhcc?useUnicode=true&characterEncoding=utf8";
    private final String USER = "hnguigu";
    private final String PASSWORD = "123456";

    @Autowired
    DataSource dataSource;

    /*数据源*/
    @Bean
    public DataSource getC3P0() throws PropertyVetoException {
        ComboPooledDataSource comboPooled = new ComboPooledDataSource();
        comboPooled.setDriverClass(DRIVERCLASS);
        comboPooled.setJdbcUrl(JDBCURL);
        comboPooled.setUser(USER);
        comboPooled.setPassword(PASSWORD);
        return comboPooled;
    }

    /*mybatis-plus工厂*/
    @Bean
    public MybatisSqlSessionFactoryBean getBean() {
        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        return bean;
    }





}
